<template>
  <el-form ref="form"  :rules="formRules" :model="exam" label-width="80px" label-position="left">
    <el-form-item label="题目" prop="title">
      <el-input type="text" v-model="exam.title" ></el-input>
    </el-form-item>
    <el-form-item label="答案" prop="answer">
      <el-input type="text" v-model="exam.answer"></el-input>
    </el-form-item>
    <el-form-item label="得分" prop="score">
      <el-input type="text" v-model="exam.score"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="warning" @click="updateExam()">修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
    export default {
      name: "UpdateNews",
      data(){
        return{
          exam:{},
          formRules:{
            title:[{required:true,message:"题目不能为空",trigger:"blur"}],
            answer:[{required:true,message:"答案不能为空",trigger:"blur"}],
            score:[{required:true,message:"得分不能为空",trigger:"blur"}]
          }
        }
      },
      methods:{
        updateExam(){
          this.$refs['form'].validate((valid)=>{
            if(valid){
              this.axios({
                method:"PUT",
                url:"/exams",
                data:this.exam
              }).then((res)=>{
                this.$message("修改成功")
                this.$router.push("/showExam")
              })
            }else{
             this.$message("修改失败")
              return;
            }
          })

        }
      },
      created() {
        this.exam=this.$route.query.exam
      }
    }
</script>

<style scoped>

</style>
